<?php 

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
 
jimport( 'joomla.application.component.model' );

class ShopModelPayment extends JModel
{
    
    var $_data;
 
    
	
	function delete($id)
	{	
		if (!$id || !is_array($id)) {
            return false;
        }
		$query = 'SELECT * FROM #__shop_payment WHERE id IN ('.implode(',', $id).')';
		$this->_db->setQuery($query);
		if ($this->_db->loadResult() != null)
		{
			
			$query = 'DELETE FROM #__shop_payment WHERE id IN ('.implode(',', $id).')';
			$this->_db->setQuery($query);
			$this->_db->query();
			
			return true;
		}
		return false;
	}
	function move($cid, $direction)
    {
        $table = &JTable::getInstance('payment', 'ShopTable');

        if (!$table->load($cid)) {
            $this->setError(JText::_('Проблема загрузки таблицы '));
            return false;
        }
        $ret = $table->move($direction);
        if( $ret != '1')  {
            $this->setError(JText::_('Невозможно переместить '));
            return false;
        }

        return true;
    }
	
	function store($data) // сохраниение информации в базе
	{
		$db= &JFactory::getDBO();
		$query = "SELECT * 
						  FROM #__shop_payment
						  WHERE id=".$data[id];
		$db->setQuery($query);
		$is_new = $db->loadResult();
		$row = $this->getTable('payment', 'ShopTable');
		$row->bind($data);
		$ordering = $row->getNextOrder();
		
		$data[description] = JRequest::getVar( 'description', '', 'post', 'string', JREQUEST_ALLOWRAW );
		$data[description] = str_ireplace('<BR mce_bogus="1">','',$data[description]);
		
		if($is_new != null) // если редактирование
		{
			$query = "UPDATE #__shop_payment SET name='".mysql_real_escape_string($data[name])."',description='".mysql_real_escape_string($data[description])."',published='".mysql_real_escape_string($data[published])."',def='".mysql_real_escape_string($data['default'])."' WHERE id=".$data[id];
			$db->setQuery($query);
			$db->query();
			return true;
		}
		else // если создание новой
		{
			$query = "INSERT INTO #__shop_payment (name,description,published,ordering,def) VALUES ('".mysql_real_escape_string($data[name])."','".mysql_real_escape_string($data[description])."','".mysql_real_escape_string($data[published])."','".$ordering."','".mysql_real_escape_string($data['default'])."')";
			$db->setQuery($query);
			$db->query();
			return true;
		
		}
			
	}
	
}
?>